package com.example.sb.service;

import com.example.sb.dao.UserDao;
import com.example.sb.pojo.User;
import org.aspectj.lang.annotation.AfterThrowing;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author kedong.lin
 */
@Service
public class UserBatchService {
    @Autowired
    private UserDao userDao;
    @Autowired
    private MybatisUserService userBatchService;

    @Autowired
    private UserBatchService userService;
    @Transactional(isolation = Isolation.READ_COMMITTED,propagation = Propagation.REQUIRED)
    public void batchSaveUser(List<User> userList){
        userService.save(userList.get(1));
        long count = userList.stream().mapToLong(user -> userBatchService.saveUser(user).getId()).count();
        System.out.println("total "+count);

    }


    @Transactional(isolation = Isolation.READ_COMMITTED,propagation = Propagation.REQUIRES_NEW)
    public int save(User user){
        return userDao.save(user);
    }
}
